<template>
	<view :class='size' class='cs-btn primary' v-if="type=='primary'" @click="onClick">{{text}}</view>
	<view :class='size' class='cs-btn warning' v-if="type=='warning'" @click="onClick">{{text}}</view>
	<view :class='size' class='cs-btn error' v-if="type=='error'" @click="onClick">{{text}}</view>
	<view :class='size' class='cs-btn default' v-if="type=='default'" @click="onClick">{{text}}</view>
	<block v-if="type=='custom'"><slot></slot></block>
</template>

<script>
	import audio from '@/lib/audio.js';
	
	export default {
		name:"csbtn",
		props: {
			type: {
				type: String,
				default: 'default',				
				validator: function(value) {
					if(value == 'primary' || value == 'warning' || value == 'error' || value == 'default' || value == 'custom'){
						return true;
					}else{
						return false;
					}
				}
			},
			text: {
				type: String,
				default: '',
				validator: function(value) {
					if(value == null || value == ''){
						return false;
					}else{
						return true;
					}
				}
			},
			size: {
				type: String,
				default: 'middle',
				validator: function(value) {
					if(value == 'small' || value == 'middle'|| value == 'big'){
						return true;
					}else{
						return false;
					}
				}
			},
			param: {
				type: Object,
				default: {}
			}
		},
		data() {
			return {
				
			};
		},
		methods:{
			onClick(e){
				console.log(e);
				audio.playClick();
				if(this.param == null){
					this.param={};
				}
				this.$emit('method', this.param);
			}
		}
	}
</script>

<style>

	.cs-btn{
		display: flex;
		flex-direction: column;
		flex-wrap: wrap;
		justify-content: flex-start;
		align-items: center;
		width: 100%;
	}
	
	.cs-btn.primary{
		background-color: #33b4ff;
		color: #fff;
	}
	
	.cs-btn.warning{
		background-color: #f39801;
		color: #fff;
	}
	
	.cs-btn.error{
		background-color: #ed1c24;
		color: #fff;
	}
	
	.cs-btn.default{
		background-color: #e1e1e1;
		color: #fff;
	}
	
	.cs-btn.big{
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		width: 100%;
		height: 50px;
		line-height: 50px;
		font-weight: bold;
		font-size: 16px;
		border-radius: 50px;
	}
	
	.cs-btn.middle{
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		width: 90%;
		height: 40px;
		line-height: 40px;
		font-size: 16px;
		border-radius: 40px;
	}
	
	.cs-btn.small{
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		width: 70%;
		font-size: 12px;
	}
</style>